package raf;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * 读取字符串
 * @author 范传奇
 *
 */
public class ReadStringDemo {
	public static void main(String[] args) throws IOException {
		RandomAccessFile raf = new RandomAccessFile("note.txt","r");
		
		byte[] data = new byte[(int)raf.length()];
		
		raf.read(data);
		/*
		 * String提供的构造方法:
		 * String(byte[] data,String csn)
		 * 将给定的字节数组中所有字节按照给定的字符集还原为字符串
		 */
		String str = new String(data,"UTF-8");
		
		System.out.println(str);
		
		raf.close();
		
	}
}
















